import Cookies from 'js-cookie'

const TokenKey = 'Admin-Token'

export function getToken() {
  return Cookies.get(TokenKey)
}

export function setToken(token) {
  return Cookies.set(TokenKey, token)
}

export function removeToken() {
  return Cookies.remove(TokenKey)
}

const UserInfo = 'UserInfo'

export function getUserInfo() {
  let userInfo = Cookies.get(UserInfo)
  if (userInfo) {
    try {
      userInfo = JSON.parse(userInfo)
    } catch (err) {
      console.log('user err')
    }
  }
  return userInfo
}

export function setUserInfo(user) {
  return Cookies.set(UserInfo, user)
}

export function removeUserInfo() {
  return Cookies.remove(UserInfo)
}
